package cn.edu.zut.cs.Utils;

import cn.edu.zut.cs.pojo.ResultMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Description:用来封装消息的工具类
 */
public class MessageUtils {
    public static String getMessage(boolean isSystemMessage,String fromName,String fromImg,Object message){
        try{
            ResultMessage result = new ResultMessage();
            result.setIsSystem(isSystemMessage);
            result.setMessage(message);
            if(fromName!=null){
                result.setFromName(fromName);
                result.setFromImg(fromImg);
            }
            ObjectMapper mapper=new ObjectMapper();
            return mapper.writeValueAsString(result);
        } catch (JsonProcessingException e){
            e.printStackTrace();
        }
        return null;
    }
}
